package  
{

	import com.*;
	import com.Logging.ClientAction;
	import com.Logging.ClientActionType;
	import com.facebook.graph.Facebook;
	import ui.popup.GCNotificationPopup;
	
	import data.*;
	
	import events.GCEvent;
	import events.GCQuestEvent;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.text.TextField;
	import flash.ui.Mouse;
	import flash.utils.Dictionary;
	import flash.utils.Timer;
	
	import org.flixel.*;
	
	import ui.AnimatedBitmap;
	import ui.button.GCButton;
	import ui.popup.GCChangeShipPopup;
	import ui.popup.GCGoalDisplayObject;
	import ui.popup.GCGoalPopup;
	import ui.popup.GCNpcPopup;
	import ui.popup.GCTextPopup;
	import ui.textfield.GCStylizedText;
	
	/**
	 * The bottom bar with buttons that will allow access to the player's
	 * ship menu and to the world map. Will also contain a place for
	 * help menus and other game options.
	 */
	public class GCBodyBar extends Sprite
	{		
		public static const COMPONENT_ID_MAP:uint = 0;
		public static const COMPONENT_ID_SHIP:uint = 1;
		public static const COMPONENT_ID_SYNTHESIZE:uint = 2;
		public static const COMPONENT_ID_UPGRADE:uint = 3;
		public static const COMPONENT_ID_INVENTORY:uint = 4;
		public static const COMPONENT_ID_ADDSHIP:uint = 5;
		public static const COMPONENT_ID_NOTIFICATION:uint = 6;
		public static const COMPONENT_ID_TASKS:uint = 7;
		
		/*
		 * The buttons on the info bar
		 */		
		private var _shipButton:GCButton;
		private var _mapButton:GCButton;
		private var _infoButton:GCButton;
		
		/*
		 * Submenu for the ship button
		 */
		private var _shipHolderSprite:Sprite;
		private var _shipInventoryButton:GCButton;
		private var _synthesizeButton:GCButton;
		private var _changeShipButton:GCButton;
		private var _shipUpgradeButton:GCButton;
		private var _trophyRoomButton:GCButton;
		private var _tasksButton:GCButton;
		private var _closeTasksButton:GCButton;
		private var _tasksDisplayArea:Sprite;
		private var _notificationButton:GCButton;
		
		/*
		 * Extra stuff, credits and toggle music
		 */
		private var _extrasHolderSprite:Sprite;
		private var _creditsButton:GCButton;
		private var _creditsPopup:GCTextPopup;
		private var _toggleMusicButton:GCButton;
		private var _toggleSfxButton:GCButton;
		private var _inviteFriendsButton:GCButton;
		
		private var _isTasksDisplayed:Boolean;
		
		/*
		 * Keep a list of current quests
		 * Key:GCQuest
		 * Value:NPC component
		 */
		private var _questsList:Dictionary;
		
		/*
		 * Blink the tasks button
		 */
		private var _blinkTimer:Timer;
		private var _blinkDelta:Number;
		private var _newTask:GCStylizedText;
		private var _newNotice:GCStylizedText;
		
		/*
		 * Stuff to blink generic buttons within the tasks bar
		 */
		private var _componentsToBlink:Vector.<Sprite>;
		private var _generalBlinkTimer:Timer;
		private var _generalBlinkDelta:Number;
		
		/*
		 * Notification screen
		 */
		private var _notificationPopup:GCNotificationPopup;
		
		/*
		 * A notification for something selling
		 */
		private var newItemSold:GCStylizedText;
		
		/*
		 * Button Constants
		 */
		private static const BUTTON_WIDTH:int = 120;
		private static const BUTTON_HEIGHT:int = 30;
		 
		
		public function GCBodyBar() 
		{
			_isTasksDisplayed = false;
			_questsList = new Dictionary();
			_newTask = new GCStylizedText();
			_newNotice = new GCStylizedText();
			
			/** Main Buttons **/ 
			
			// Ship button
			_shipButton = new GCButton(onClickShipSubMenu);
			_shipButton.loadGraphic(GCResources.plate, BUTTON_WIDTH, BUTTON_HEIGHT);
			_shipButton.loadText("Ship");
			_shipButton.x = 10;
			_shipButton.y = -5;
			this.addChild(_shipButton);
			_shipButton.addEventListener(MouseEvent.ROLL_OVER, onHoverOverShip);
			_shipButton.addEventListener(MouseEvent.ROLL_OUT, onHoverOutShip);
			
			// World map button
			_mapButton = new GCButton(onClickDisplayWorldMap);
			_mapButton.loadGraphic(GCResources.plate, BUTTON_WIDTH, BUTTON_HEIGHT);
			_mapButton.loadText("Map");
			_mapButton.x = _shipButton.x + _shipButton.width + 10;
			_mapButton.y = _shipButton.y;
			this.addChild(_mapButton);
			
			// Info Button
			_infoButton = new GCButton(onClickDisplayInfo);
			_infoButton.loadGraphic(GCResources.plate, BUTTON_WIDTH, BUTTON_HEIGHT);
			_infoButton.loadText("Extras");
			_infoButton.x = _mapButton.x + _mapButton.width + 10;
			_infoButton.y = _mapButton.y;
			this.addChild(_infoButton);
			_infoButton.addEventListener(MouseEvent.ROLL_OVER, onHoverOverExtras);
			_infoButton.addEventListener(MouseEvent.ROLL_OUT, onHoverOutExtras);
			
			// Tasks Button
			_tasksButton = new GCButton(onClickTasks);
			_tasksButton.loadGraphic(GCResources.plate, BUTTON_WIDTH, BUTTON_HEIGHT);
			_tasksButton.loadText("Tasks");
			_tasksButton.x = _infoButton.x + _infoButton.width + 10;
			_tasksButton.y = _infoButton.y;
			_tasksDisplayArea = new Sprite();
			this.addChild(_tasksButton);
			
			_tasksDisplayArea.graphics.beginFill(0x000000, 0.4);
			_tasksDisplayArea.graphics.drawRect(0, 0, 120, FlxG.height);
			_tasksDisplayArea.x = FlxG.width - _tasksDisplayArea.width;
			
			_closeTasksButton = new GCButton(onClickTasks);
			_closeTasksButton.loadGraphic(GCResources.plate, 120, BUTTON_HEIGHT);
			_closeTasksButton.loadText("Close Tasks");
			_closeTasksButton.buttonMode = true;
			_tasksDisplayArea.addChild(_closeTasksButton);
			
			// Notifications
			_notificationButton = new GCButton(onClickNotifications);
			_notificationButton.loadGraphic(GCResources.plate, BUTTON_WIDTH, BUTTON_HEIGHT);
			_notificationButton.loadText("Notifications");
			_notificationButton.x = _tasksButton.x + _tasksButton.width + 10;
			_notificationButton.y = _tasksButton.y;
			this.addChild(_notificationButton);
			_tasksDisplayArea.y = -1 * (FlxG.height - this.height);
			
			_notificationPopup = new GCNotificationPopup();
			
			
			/** Ship Drop Down Menu Buttons **/
			// Opens buttons to view inventory, synthesize items and repair ship
			
			// Build the container for the menu
			_shipHolderSprite = new Sprite();
			_shipHolderSprite.x = 0;
			_shipHolderSprite.y = -_shipButton.height * 4;
			
			// Create the sprite for inventory button
			_shipInventoryButton = new GCButton(onClickInventory);
			_shipInventoryButton.loadGraphic(GCResources.plate, BUTTON_WIDTH, BUTTON_HEIGHT);
			_shipInventoryButton.loadText("Inventory");
			_shipHolderSprite.addChild(_shipInventoryButton);
			
			// Create the sprite for the synthesize button
			_synthesizeButton = new GCButton(onClickSynthesize);
			_synthesizeButton.loadGraphic(GCResources.plate, BUTTON_WIDTH, BUTTON_HEIGHT);
			_synthesizeButton.loadText("Synthesize");
			_synthesizeButton.y = _shipButton.height;
			_shipHolderSprite.addChild(_synthesizeButton);
			
			// Create the sprite for the ship repair button
			_shipUpgradeButton = new GCButton(onClickRepair);
			_shipUpgradeButton.loadGraphic(GCResources.plate, BUTTON_WIDTH, BUTTON_HEIGHT);
			_shipUpgradeButton.loadText("Ship Upgrade");
			_shipUpgradeButton.y = _shipButton.height * 2;
			_shipHolderSprite.addChild(_shipUpgradeButton);
			
			// Create the sprite for the Change Ship button
			_changeShipButton = new GCButton(onClickChangeShip);
			_changeShipButton.loadGraphic(GCResources.plate, BUTTON_WIDTH, BUTTON_HEIGHT);
			_changeShipButton.loadText("Change Ship");
			_changeShipButton.y = _shipButton.height * 3;
			_shipHolderSprite.addChild(_changeShipButton);
			
			_shipHolderSprite.graphics.beginFill(GCConstants.COLOR_BROWN, 0.5);
			_shipHolderSprite.graphics.drawRoundRect(0, 0, _shipHolderSprite.width, _shipHolderSprite.height, 20);
			_shipHolderSprite.graphics.endFill();
			
			// Holder for extras options
			_extrasHolderSprite = new Sprite();
			var yOffset:int = 0;
			_creditsButton = new GCButton(onClickCredits);
			_creditsButton.y = yOffset;
			_creditsButton.loadGraphic(GCResources.plate, BUTTON_WIDTH, BUTTON_HEIGHT);
			_creditsButton.loadText("Credits");
			yOffset += _creditsButton.height;
			
			_toggleMusicButton = new GCButton(onToggleMusic);
			_toggleMusicButton.y = yOffset;
			_toggleMusicButton.loadGraphic(GCResources.plate, BUTTON_WIDTH, BUTTON_HEIGHT);
			_toggleMusicButton.loadText("Toggle Music");
			yOffset += _toggleMusicButton.height;
			
			_toggleSfxButton = new GCButton(onToggleSfx);
			_toggleSfxButton.y = yOffset;
			_toggleSfxButton.loadGraphic(GCResources.plate, BUTTON_WIDTH, BUTTON_HEIGHT);
			_toggleSfxButton.loadText("Toggle SFX");
			yOffset += _toggleSfxButton.height;
			
			_inviteFriendsButton = new GCButton(onInviteFriends);
			_inviteFriendsButton.y = yOffset;
			_inviteFriendsButton.loadGraphic(GCResources.plate, BUTTON_WIDTH, BUTTON_HEIGHT);
			_inviteFriendsButton.loadText("Invite Friends");
			yOffset += _inviteFriendsButton.height;
			
			if (!GCConstants.FACEBOOK_INTEGRATED)
			{
				_inviteFriendsButton.disable();
			}
			
			_extrasHolderSprite.addChild(_toggleMusicButton);
			_extrasHolderSprite.addChild(_creditsButton);
			_extrasHolderSprite.addChild(_toggleSfxButton);
			_extrasHolderSprite.addChild(_inviteFriendsButton);
			_extrasHolderSprite.y = -1 * _extrasHolderSprite.height;
			_extrasHolderSprite.graphics.beginFill(GCConstants.COLOR_BROWN, 0.5);
			_extrasHolderSprite.graphics.drawRoundRect(0, 0, _extrasHolderSprite.width, _extrasHolderSprite.height, 20);
			_extrasHolderSprite.graphics.endFill();
			
			// Blinker
			_blinkTimer = new Timer(100);
			_blinkDelta = -0.1;
			_blinkTimer.addEventListener(TimerEvent.TIMER, onBlink);
			
			
			
			
			/*
			 * TODO:
			 * Insert a trophy room button here
			 */
			_trophyRoomButton = new GCButton();
			
			/*
			 * General Blinking
			 */
			_componentsToBlink = new Vector.<Sprite>();
			_generalBlinkTimer = new Timer(100);
			_generalBlinkDelta = -0.1;
			_generalBlinkTimer.addEventListener(TimerEvent.TIMER, onGenericBlink);
			
			/*
			 * Roy-- tutorial
			 * Disable certain body bar buttons depending on tutorial sequence
			 */
			_mapButton.disable();
			_shipButton.disable();
			_synthesizeButton.disable();
			_shipUpgradeButton.disable();
			_changeShipButton.disable();
			if (GCPlayState.tutorialSequence.currentTutorialStage >= GCTutorial.STAGE_FIRST_JOURNEY)
			{
				this.enableMap();
				this.enableShip();
			}
			
			if (GCPlayState.tutorialSequence.currentTutorialStage >= GCTutorial.STAGE_ESTABLISH_NEW_CENTER)
			{
				this.enableRecipesAndUpgrades();
			}
			
			// new tasks indicator
			_newTask.setBgStyle(GCStylizedText.STYLE_NEW_TASKS, _tasksButton.width, 20);
			_newTask.topPadding = 0;
			_newTask.text = "New Tasks!";
			_newTask.x = _tasksButton.x;
			_newTask.y = _tasksButton.y - _newTask.height + 5;
			
			// item sold indicator
			_newNotice.setBgStyle(GCStylizedText.STYLE_NEW_TASKS, _notificationButton.width, 20);
			_newNotice.topPadding = 0;
			_newNotice.text = "Item Sold!";
			_newNotice.x = _notificationButton.x;
			_newNotice.y = _notificationButton.y - _newNotice.height + 5;
		}
		
		//----------------------------------------------------------------------
		//	PUBLIC FUNCTIONS
		//----------------------------------------------------------------------
		
		/** Tasks **/
		
		/**
		 * Add a new quest to the information bar.
		 */
		public function addQuest(quest:GCQuest):void
		{
			// Blink tasks button to indicate new task
			_blinkTimer.start();
			_tasksButton.graphics.beginFill(GCConstants.COLOR_RED);
			_tasksButton.graphics.drawRoundRect(10, 5, _tasksButton.width - 20, _tasksButton.height - 12, 5);
			_tasksButton.graphics.endFill();
			if (_newTask.parent == null)
				this.addChild(_newTask);
			_newTask.visible = true;
				
			var o:Object = new Object();
			var questComponent:GCGoalDisplayObject;
			if (quest.questType == GCQuestData.QUEST_TYPE_NPCORDER ||
				quest.questType == GCQuestData.QUEST_TYPE_TUTORIAL_ORDER)
			{
				trace("Adding a new order quest!");
				questComponent = new GCNpcPopup(quest)
				questComponent.addEventListener(GCEvent.REFRESH_MENU_EVENT, onMenuChanged);
				_questsList[quest] = questComponent;
				
				if (GCConstants.LOGGING_DATA)
				{
					o["templateId"] = quest.templateId;
					o["timeLeft"] = quest.timeRemaining;
					o["reqItem"] = quest.goalId;
					o["reqQty"] = quest.goalQuantity;
					o["rewItem"] = quest.rewardId;
					o["rewQty"] = quest.rewardAmount;
					GCPlayState.logger.LogAction(new ClientAction(ClientActionType.ASSIGN_NPC_ORDER, o));
				}
			}
			else
			{
				trace("Adding a new goal quest");
				questComponent = new GCGoalPopup(quest);
				_questsList[quest] = questComponent;
				
				if (GCConstants.LOGGING_DATA)
				{
					o["templateId"] = quest.templateId;
					GCPlayState.logger.LogAction(new ClientAction(ClientActionType.ASSIGN_GOAL, o));
				}
			}
			
			questComponent.addEventListener(GCEvent.QUEST_RESOLVED_EVENT, onQuestResolved);
		}
		
		/**
		 * Remove a quest if its time limit has expired or the player has
		 * successfully completed it.
		 */
		public function removeQuest(quest:GCQuest):void
		{
			var displayComponent:GCGoalDisplayObject = _questsList[quest] as GCGoalDisplayObject;
			if (displayComponent.parent != null)
				_tasksDisplayArea.removeChild(displayComponent);
			displayComponent.cleanUp();
			delete _questsList[quest];
			
			if (_isTasksDisplayed) 
			{
				_isTasksDisplayed = false;
				removeChild(_tasksDisplayArea);
			}
		}
		
		public function getQuestsList():Dictionary
		{
			return _questsList;
		}
		
		/** Notifications **/
		
		public function addNotification(newNotice:String, isSale:Boolean = false):void
		{
			if (_newNotice.parent == null)
			{
				this.addChild(_newNotice);
				_newNotice.visible = false;
			}
			if (isSale)
			{
				_newNotice.visible = true;
			}
			_notificationPopup.addNotice(newNotice + "\n", isSale);
		}
		
		
		/** Buttons **/		
		public function enableMap():void
		{
			_mapButton.enable();
		}
		
		public function enableShip():void
		{
			_shipButton.enable();
		}
		
		public function enableRecipesAndUpgrades():void
		{
			_synthesizeButton.enable();
			_shipUpgradeButton.enable();
			_changeShipButton.enable();
		}
		
		//----------------------------------------------------------------------
		//	PRIVATE FUNCTIONS
		//----------------------------------------------------------------------		
		
		/**
		 * Triggered when the quest is resolved in some fashion, either
		 * the time expired or it was successfully completed.
		 */
		private function onQuestResolved(event:GCQuestEvent):void
		{
			var component:GCNpcPopup = event.currentTarget as GCNpcPopup
			
			trace("GCInformationBar-- Quest has been resolved!");
			
			// Remove the quest from the display list
			//removeQuest(component.getQuest());
			
			// Close the task area, a bit of a hack so we don't need to dynamically
			//shift things up
			if (_isTasksDisplayed) 
			{
				_isTasksDisplayed = false;
				removeChild(_tasksDisplayArea);
			}
			
			//Bubble up the event to the play state class
			var questEvent:GCQuestEvent = new GCQuestEvent(GCEvent.QUEST_RESOLVED_EVENT);
			questEvent.quest = component.getQuest();
			questEvent.successfullyCompleted = event.successfullyCompleted;
			dispatchEvent(questEvent);			
		}
		
		/**
		 * Function to blink the tasks button
		 */
		private function onBlink(event:TimerEvent):void
		{
			if (_tasksButton.alpha >= 1.0 && _blinkDelta > 0)
			{
				_blinkDelta *= -1.0;
			}
			else if (_tasksButton.alpha < 0.5 && _blinkDelta < 0)
			{
				_blinkDelta *= -1.0;
			}
			_tasksButton.alpha += _blinkDelta;
		}	
		
		public function startBlinking(componentId:uint):void
		{
			var component:Sprite;
			switch(componentId)
			{
				case COMPONENT_ID_MAP:
					component = _mapButton;
					break;
				case COMPONENT_ID_SHIP:
					component = _shipButton;
					break;
				case COMPONENT_ID_SYNTHESIZE:
					component = _synthesizeButton;
					break;
				case COMPONENT_ID_UPGRADE:
					component = _shipUpgradeButton;
					break;
				case COMPONENT_ID_NOTIFICATION:
					component = _notificationButton;
					break;
			}
			
			if (component == null)
				return
			
			component.graphics.beginFill(GCConstants.COLOR_BLUE);
			component.graphics.drawRoundRect(10, 5, _tasksButton.width - 20, _tasksButton.height - 12, 5);
			component.graphics.endFill();
			_componentsToBlink.push(component);
			
			if (!_generalBlinkTimer.running)
				_generalBlinkTimer.start();
		}
		
		private function killBlink(component:Sprite):void
		{
			if (_componentsToBlink.indexOf(component, 0) >= 0)
			{
				_componentsToBlink.splice(_componentsToBlink.indexOf(component), 1);
				component.graphics.clear();
				component.alpha = 1.0;
			}
			else
			{
				return;
			}
			
			if (_componentsToBlink.length == 0)
			{
				_generalBlinkTimer.stop();
			}
		}

		private function onGenericBlink(event:TimerEvent):void
		{
			for each (var component:Sprite in _componentsToBlink)
			{
				if (component.alpha >= 1.0 && _blinkDelta > 0)
				{
					_blinkDelta *= -1.0;
				}
				else if (component.alpha < 0.5 && _blinkDelta < 0)
				{
					_blinkDelta *= -1.0;
				}
				component.alpha += _blinkDelta;
			}
		}
		
		//----------------------------------------------------------------------
		//	EVENT HANDLERS
		//----------------------------------------------------------------------
		
		/** Menu Switching Events **/
		
		// Opens and closes the ship submenus
		private function onClickShipSubMenu(event:MouseEvent):void
		{
			(_shipHolderSprite.visible) ? onHoverOutShip(event) : onHoverOverShip(event);
		}
		
		private function onHoverOverShip(event:MouseEvent):void
		{
			if (_shipHolderSprite.parent == null)
			{
				_shipButton.addChild(_shipHolderSprite);
			}
			_shipHolderSprite.visible = true;
			
			killBlink(_shipButton);
		}
		
		private function onHoverOutShip(event:MouseEvent):void
		{
			_shipHolderSprite.visible = false;
		}
		
		private function onHoverOverExtras(event:MouseEvent):void
		{
			if (_extrasHolderSprite.parent == null)
			{
				_infoButton.addChild(_extrasHolderSprite);
			}
			
			_extrasHolderSprite.visible = true;
		}
		
		private function onHoverOutExtras(event:MouseEvent):void
		{
			_extrasHolderSprite.visible = false;
		}
		
		// Call to display the inventory menu
		private function onClickInventory(event:MouseEvent):void
		{
			dispatchEvent(new Event(GCEvent.OPEN_SHIP_INVENTORY_EVENT));
			
			killBlink(_shipInventoryButton);
		}
		
		// Call to display the synthesize menu
		private function onClickSynthesize(event:MouseEvent):void
		{
			dispatchEvent(new Event(GCEvent.OPEN_SYNTHESIZE_EVENT));
			
			killBlink(_synthesizeButton);
		}
		
		// Call to display the ship repair menu		
		private function onClickRepair(event:MouseEvent):void
		{
			if (GCConstants.LOGGING_DATA)
			{
				GCPlayState.logger.LogAction(new ClientAction(ClientActionType.VIEW_SHIP));
			}
			dispatchEvent(new Event(GCEvent.OPEN_SHIP_REPAIR_EVENT));
			
			killBlink(_shipUpgradeButton);
		}
		
		// Call to display the world map
		private function onClickDisplayWorldMap(event:MouseEvent):void
		{
			dispatchEvent(new Event("Display World Map"));
			
			killBlink(_mapButton);
		}
		
		// Call to display info menu
		private function onClickDisplayInfo(event:MouseEvent):void
		{
			//dispatchEvent(new Event("Display Info"));
			(_extrasHolderSprite.visible) ? onHoverOutExtras(event) : onHoverOverExtras(event);
		}
		
		// Call to display trophy room
		private function onClickTrophyRoom(event:MouseEvent):void
		{
			dispatchEvent(new Event(GCEvent.OPEN_TROPHY_ROOM_EVENT));
		}
		
		
		/** Body bar Handling Events **/

		// Call to open the notifications screen
		private function onClickNotifications(event:MouseEvent):void
		{
			if (_notificationPopup.parent == null)
			{
				_notificationPopup.x = _notificationButton.x;
				_notificationPopup.y = -1 * _notificationPopup.viewableHeight;
				addChild(_notificationPopup)
			}
			else
			{
				_notificationPopup.visible = !_notificationPopup.visible
			}

			_newNotice.visible = false;
			killBlink(_notificationButton);
			
			if (GCConstants.LOGGING_DATA)
			{
				GCPlayState.logger.LogAction(new ClientAction(ClientActionType.VIEW_NOTIF));
			}
		}

		// Opens and closes the task bar
		private function onClickTasks(event:MouseEvent):void
		{
			//Stop the blink
			_blinkTimer.stop();
			_newTask.visible = false;
			_tasksButton.graphics.clear();
			_tasksButton.alpha = 1.0;
			
			if (_isTasksDisplayed)
			{
				_isTasksDisplayed = false;
				removeChild(_tasksDisplayArea);
				
				while (_tasksDisplayArea.numChildren > 1)
				{
					_tasksDisplayArea.removeChildAt(1);
				}
			}
			else
			{
				_isTasksDisplayed = true;
				addChild(_tasksDisplayArea);
				
				var xPos:int = 10;
				var yPos:int = _closeTasksButton.height;
				for each (var component:GCGoalDisplayObject in _questsList)
				{
					trace("Adding a quest to display");
					component.x = xPos;
					component.y = yPos;
					
					yPos += component.height + 10;
					_tasksDisplayArea.addChild(component);
				}
			}
		}
		
		// Opens up popup to change ship
		private function onClickChangeShip(event:MouseEvent):void
		{
			var popup:GCChangeShipPopup = new GCChangeShipPopup();
			popup.addEventListener(GCEvent.CHANGE_ACTIVE_SHIP_EVENT, onMenuChanged);
			GCPlayState.disableScreen(popup);
		}
		
		// Opens the game credits
		private function onClickCredits(event:MouseEvent):void
		{
			var credits:String = GCConstants.DEVELOPERS + "\n" + GCConstants.ARTIST + "\n" + GCConstants.MISC_ACKNOWLEDGEMENTS;
			_creditsPopup = new GCTextPopup(credits, GCPlayState.enableScreen);
			GCPlayState.disableScreen(_creditsPopup);
		}
		
		// Turns on and off music
		private function onToggleMusic(event:MouseEvent):void
		{
			var bgMusic:FlxSound = FlxG.music;
			
			(bgMusic.playing) ? bgMusic.pause() : bgMusic.play();
		}
		
		// Turn on and off sfx
		private function onToggleSfx(event:MouseEvent):void
		{
			GCUtil._playSoundEffects = !GCUtil._playSoundEffects;
		}
		
		// Click here to invite a friend
		private function onInviteFriends(event:MouseEvent):void
		{
			var dat:Object = new Object();
			dat.message = "Invite Friends to Play Free Traders!";
			dat.title   = 'Free Traders';
			// filtering for non app users only
			dat.filters = ['app_non_users'];
			//You can use these two options for diasplaying friends invitation window 'iframe' 'popup'
			Facebook.ui('apprequests', dat, onInviteCallback, 'popup');
		}
		
		private function onInviteCallback(result:Object):void
		{
			if (result == null)
			{
				return;
			}
			
			var invitedUsers:Array  = new Array();
			invitedUsers = result.request_ids as Array;
			trace('You Have Invited ', invitedUsers.length,' friends');
		}
		
		/** Misc. **/
		
		// Call to refresh the menu
		private function onMenuChanged(event:Event):void
		{
			dispatchEvent(new Event(GCEvent.REFRESH_MENU_EVENT));
		}
		
	}
}